//
//  OESetpwdViewController.m
//  OneEightyNine
//
//  Created by apple on 2019/3/6.
//  Copyright © 2019 stoneobs. All rights reserved.
//

#import "OESetpwdViewController.h"
#import "STPasswordTextField.h"
@interface OESetpwdViewController ()
@property(nonatomic, strong) STPasswordTextField                     *textFiled;/**< <##> */
@end

@implementation OESetpwdViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = OESTRING(@"PAYMENT SETTTING");
    [self configSubView];
    // Do any additional setup after loading the view.
}
#pragma mark --configSubView
- (void)configSubView{
    [self st_autoAdjustAllResponder];
    
    __weak typeof(self) weakSelf =  self;
    UIView * footer = [[UIView alloc] initWithFrame:CGRectMake(0, 0, UIScreenWidth, 100)];
    
    STLabel * titleLabel = [[STLabel alloc] initWithFrame:CGRectMake(0, 100, UIScreenWidth, 40)
                                                    text:OESTRING(@"Set 6 digit payment password")
                                               textColor:FirstTextColor
                                                    font:16
                                             isSizetoFit:NO
                                           textAlignment:NSTextAlignmentCenter];
    
    [footer addSubview:titleLabel];
    
    self.textFiled = [[STPasswordTextField alloc] initWithFrame:CGRectMake(20, titleLabel.bottom, UIScreenWidth - 40, 50) passwordLength:6];
    self.textFiled.secureTextEntry = YES;
    [footer addSubview:self.textFiled];
    
    
    STButton * button = [[STButton alloc] initWithFrame:CGRectMake(20, self.textFiled.bottom + 20, UIScreenWidth - 40, 50)
                                                  title:@"COMPLETE"
                                             titleColor:UIColor.whiteColor
                                              titleFont:15
                                           cornerRadius:25
                                        backgroundColor:OE_LIMITE_COLOR
                                        backgroundImage:nil
                                                  image:nil];
    button.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
    button.centerX = self.tableView.width / 2;
    footer.height = button.bottom + 20;
    [footer addSubview:button];
    [button setClicAction:^(UIButton *sender) {
        [weakSelf onSelctedConfimButton];
    }];
    self.tableView.tableFooterView = footer;
}
#pragma mark --Action Method
- (void)onSelctedConfimButton{
    if (self.textFiled.text.length == 6) {
        [OEUserDataController sendChangePayPwdRequest:self.textFiled.text hadle:^(BOOL success, NSString *errorString, NSDictionary *resp) {
            if (success) {
                [SVProgressHUD showSuccessWithStatus:@"set success"];
                dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
                    [self.navigationController popViewControllerAnimated:YES];
                });
            }
        }];
    }else{
        [SVProgressHUD showInfoWithStatus:@"please input thue password"];
    }
}
@end
